﻿
Imports System.IO
Imports xmlctrl

Public Module unittests
    Public Function firstpage(ByRef buff As MemoryStream) As xmlcontrol
        Dim doc As container = Nothing
        doc = New container(buff)

        Dim xml As xml = Nothing
        xml = New xml(buff)
        xml.version = "1.1"
        xml.encoding = encoding.name.utf8
        doc.addchild(xml)

        Dim doctype As doctype = Nothing
        doctype = New doctype(buff)
        doc.addchild(doctype)

        Dim html As html = Nothing
        html = New html(buff)
        html.xml_lang = "en"
        doc.addchild(html)

        Dim head As head = Nothing
        head = New head(buff)
#If CANNOT_DETERMINE Then
        head.id = "id_head"
#End If
        html.addchild(head)

        Dim title As title = Nothing
        title = New title(buff)
#If CANNOT_DETERMINE Then
        title.id = "id_title"
#End If
        title.text = StrReverse("this is the title of firstpage")
        head.addchild(title)

        Dim body As body = Nothing
        body = New body(buff)
        body.id = "id_body"
        html.addchild(body)

        Dim div As div = Nothing
        div = New div(buff)
        div.id = "id_div"
        body.addchild(div)

        Dim p As p = Nothing
        p = New p(buff)
        p.id = "id_p"
        p.text = StrReverse("this is the body of firstpage")
        div.addchild(p)

        Dim br As br = Nothing
        br = New br(buff)
        div.addchild(br)

        Dim big As big = Nothing
        big = New big(buff)
        big.id = "id_big"
        big.dir = xhtmlControl_1_1_shared.dir_enum.rtl
        big.text = StrReverse("this is a big, which is placed in div")
        div.addchild(big)

        Dim h1 As h1 = Nothing
        h1 = New h1(buff)
        h1.id = "id_h1_1"
        h1.text = StrReverse("this is h1_1")
        div.addchild(h1)

        Dim h2 As h2 = Nothing
        h2 = New h2(buff)
        h2.id = "id_h2_1"
        h2.text = StrReverse("this is h2_1")
        div.addchild(h2)

        Dim h3 As h3 = Nothing
        h3 = New h3(buff)
        h3.id = "id_h3_1"
        h3.text = StrReverse("this is h3_1")
        div.addchild(h3)

        h3 = New h3(buff)
        h3.id = "id_h3_2"
        h3.text = StrReverse("this is h3_2")
        div.addchild(h3)

        h2 = New h2(buff)
        h2.id = "id_h2_2"
        h2.text = StrReverse("this is h2_2")
        div.addchild(h2)

        h3 = New h3(buff)
        h3.id = "id_h3_3"
        h3.text = StrReverse("this is h3_3")
        div.addchild(h3)

        h3 = New h3(buff)
        h3.id = "id_h3_4"
        h3.text = StrReverse("this is h3_4")
        div.addchild(h3)

        h1 = New h1(buff)
        h1.id = "id_h1_2"
        h1.text = StrReverse("this is h1_2")
        div.addchild(h1)

        h2 = New h2(buff)
        h2.id = "id_h2_3"
        h2.text = StrReverse("this is h2_3")
        div.addchild(h2)

        h3 = New h3(buff)
        h3.id = "id_h3_5"
        h3.text = StrReverse("this is h3_5")
        div.addchild(h3)

        h3 = New h3(buff)
        h3.id = "id_h3_6"
        h3.text = StrReverse("this is h3_6")
        div.addchild(h3)

        h2 = New h2(buff)
        h2.id = "id_h2_4"
        h2.text = StrReverse("this is h2_4")
        div.addchild(h2)

        h3 = New h3(buff)
        h3.id = "id_h3_7"
        h3.text = StrReverse("this is h3_7")
        div.addchild(h3)

        h3 = New h3(buff)
        h3.id = "id_h3_8"
        h3.text = StrReverse("this is h3_8")
        div.addchild(h3)

        Dim form As form = Nothing
        form = New form(buff)
        form.action = "/test"
        form.id = "id_form"
        div.addchild(form)

        Dim input As input = Nothing
        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.text
        input.id = "id_input_text"
        input.name = "name_input_text"
        input.value = StrReverse("this is an input of text")
        form.addchild(input)

        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.password
        input.id = "id_input_password"
        input.name = "name_input_password"
        input.value = StrReverse("this is an input of password")
        form.addchild(input)

        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.button
        input.id = "id_input_button"
        input.name = "name_input_button"
        input.value = StrReverse("this is an input of button")
        form.addchild(input)

        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.submit
        input.id = "id_input_submit"
        input.name = "name_input_submit"
        input.value = StrReverse("this is an input of submit")
        form.addchild(input)

        br = New br(buff)
        div.addchild(br)

        Dim table As table = Nothing
        table = New table(buff)
        table.id = "id_table"
        table.width = 512
        table.frame = xhtmlControl_1_1.frame_enum.box
        div.addchild(table)

        Dim tr As tr = Nothing
        tr = New tr(buff)
        tr.id = "id_tr_1"
        table.addchild(tr)

        Dim td As td = Nothing
        td = New td(buff)
        td.id = "id_td_1"
        td.text = StrReverse("this is td_1")
        tr.addchild(td)

        td = New td(buff)
        td.id = "id_td_2"
        td.text = StrReverse("this is td_2")
        tr.addchild(td)

        tr = New tr(buff)
        tr.id = "id_tr_2"
        table.addchild(tr)

        td = New td(buff)
        td.id = "id_td_3"
        td.text = StrReverse("this is td_3")
        tr.addchild(td)

        td = New td(buff)
        td.id = "id_td_4"
        td.text = StrReverse("this is td_4")
        tr.addchild(td)

        div = New div(buff)
        div.id = "id_div_copyright"
        div.text = StrReverse("copyright, Hzj_jie, @ http://hzj-jie.gicp.net/hzj-jie-t43, - Gemini -")
        body.addchild(div)

        Dim img As img = Nothing
        img = New img(buff)
        img.id = "id_img"
        img.src = "/favicon.ico"
        div.addchild(img)

        Return doc
    End Function

    Public Sub firstpage()
        Dim doc As xmlcontrol = Nothing
        doc = firstpage(Nothing)
        Console.WriteLine(doc.ToString())
    End Sub

    Public Function submitpage(ByRef buff As MemoryStream) As xmlcontrol
        Dim doc As container = Nothing
        doc = New container(buff)

        Dim xml As xml = Nothing
        xml = New xml(buff)
        xml.version = "1.1"
        xml.encoding = encoding.name.utf8
        doc.addchild(xml)

        Dim doctype As doctype = Nothing
        doctype = New doctype(buff)
        doc.addchild(doctype)

        Dim html As html = Nothing
        html = New html(buff)
        html.xml_lang = "en"
        doc.addchild(html)

        Dim head As head = Nothing
        head = New head(buff)
        html.addchild(head)

        Dim title As title = Nothing
        title = New title(buff)
        title.text = StrReverse("this is the title of firstpage")
        head.addchild(title)

        Dim body As body = Nothing
        body = New body(buff)
        body.id = "id_body"
        html.addchild(body)

        Dim form As form = Nothing
        form = New form(buff)
        form.id = "id_form"
        form.action = "/submit"
        html.addchild(form)

        Dim input As input = Nothing
        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.text
        input.id = "id_input_text"
        input.name = "text"
        input.value = "this is an input of text"
        form.addchild(input)

        input = New input(buff)
        input.type = xhtmlctrl.input.type_enum.submit
        input.id = "id_input_button"
        input.name = ""
        input.value = "submit"
        form.addchild(input)

        Return doc
    End Function

    Public Sub submitpage()
        Dim doc As xmlcontrol = Nothing
        doc = submitpage(Nothing)

        Console.WriteLine(doc.ToString())
    End Sub
End Module
